<?php
require('../util/ClientUtil.php');
$serv = new swoole_server('0.0.0.0',9501);
//设置异步任务的工作进程数量
$serv->set(array('task_worker_num' => 4));
$serv->on('receive',function($serv,$fd,$reactor_id,$data){
	//数据处理过程
	$dbResult = (new ClientUtil(9502))->callForReturn($data);
	$serv->send($fd,$dbResult);

});

//处理异步任务
$serv->on('task', function ($serv, $task_id, $from_id, $data) {
    echo "New AsyncTask[id=$task_id]".PHP_EOL;
    //返回任务执行的结果
    $serv->finish("$data -> OK");
});

//处理异步任务的结果
$serv->on('finish', function ($serv, $task_id, $data) {
    echo "AsyncTask[$task_id] Finish: $data".PHP_EOL;
});

$serv->start();